<script>
	import {mapState, mapMutations} from 'vuex'
	export default {
		...mapState(['userInfo', 'globalConfig']),
		onLaunch: function(e) {
			if (e.query.uid) {
				uni.setStorageSync('parent', e.query.uid);
			}
			this.init();
			this.updateUser();
		},
		methods: {
			...mapMutations(['login', 'setGlobalConfig']),
			init() {
				this.$http.get('api/default/config').then((result) => {
					uni.setStorageSync('CONFIG', result.config);
					uni.setStorageSync('tplPageSetting', result.settingData.tpl);
					uni.setStorageSync('superCate', result.settingData.super_cate);
					// #ifdef H5
					uni.setStorageSync('tabbar', result.settingData.tabbar);
					// #endif
					this.setGlobalConfig(result.config);
					
					// #ifdef MP-WEIXIN || MP-QQ
					this.resetConfig(result.config);
					// #endif
				}).catch((error) => {

				});
			},
			updateUser() {
				uni.getStorage({
					key: "user",
					success: (res) => {
						this.$http.get('api/user/userinfo').then((result) => {
							this.login(result);
						}).catch((error) => {
							this.login(res.data);
						});
					}
				});
			},
			resetConfig(config){
				uni.getStorage({
					key: "userInfo",
					success: (res) => {
						let userInfo = res.data;
						if (userInfo.account.user_money > 0 && config.wechat_mod == 0) {
							config.wechat_mod = 1;
							this.setGlobalConfig(config);
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	@import "static/style/icon.css";
	@import "static/style/app.css";

	::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}
</style>
